/**
 * role-edit.js
 */

define('url-edit',['jquery','base','liger.messageBox','liger.dialog','liger.all'],function(require, exports, module){
	var Base = require("base");
	var $ = require("jquery");
	require("liger.all")($);
	var ctx = Base.common.utils.getContextPath();
	
	var dialog = frameElement.dialog;
	
	var btns = [{text:'保存', 
	       		click : function() {
	  			var form = liger.get("form");
				var data = form.getData();
				var param = {data:liger.toJSON(data)};
		        $.ajax({
		    		url: ctx+ '/url/save.do',
		    		type : 'POST',
		    		dataType : 'json',
		    		data : param,
		    		success : function(backData) {
		    			if(backData){
		    				window.parent.jQuery("#dataGrid").ligerGetGridManager().reload();
		    			}}});}}
	    			,{text:'取消',
	            		click : function() {
	            			dialog.close();
	            		}
	                }];
	
	var $form = $("#form").ligerForm({
        inputWidth: 170, labelWidth: 90, space: 40,
         fields: [
         { name: "id", type: "hidden" },
         { display: "名称", name: "name", newline: true, type: "text" , group: "Url信息", groupicon: 'groupicon'}, 
         { display: "url", name: "url", newline: false, type: "text"},
         { display: "类型", name: "type", newline: true, type: "select", 
       	  options:{
       		  data : [{text:'按钮',id:'1'},{text:'页面',id:'2'},{text:'链接',id:'3'},{text:'默认',id:'0'}]}
         } ,
         { display: "上级", name: "parentId", newline: false, type: "select", 
       	  options:{
                 width: 180,
                 selectBoxWidth: 200,
                 selectBoxHeight: 200, valueField: 'id',textFiel:'name', 
                 treeLeafOnly:true,
                 tree: { url: ctx + '/url/queryForChileren.do?id=0', ajaxType: 'post',
               	 single:true,
               	 textFieldName:'name',
               	 idFieldName:'id',
               	 checkbox:true,
               	 isLeaf : function(data) {
               		 debugger;
	                         if (!data) return false;
	                         return data.type == "parentId";
                     		},
                 delay: function(e)  {
                	 debugger; 
                         var data = e.data;
                         return { url: ctx + '/url/queryForChileren.do?id=' + data.id };
                        
                     }
                 }
       	  }}],buttons:btns
		}); 
	
	loadModifyData();
	
	function loadModifyData(){
		if(id){
			 $.ajax({
		    		url: ctx+ '/url/load.do',
		    		type : 'POST',
		    		dataType : 'json',
		    		data : {id:id},
		    		success : function(backData) {
		    			if(backData){
		    				$form.setData(backData);
		    			}
		    		}
		        });
		}
	}
	
});